if(!lanYun){var lanYun = {ver:1.2}};
lanYun.debugtoken = '4683236968b0d4eea8aa5650a21e44dc645e9dff4fa9ffd6146f4f3573c12c9f';
lanYun.apiUrl = 'http://txs7.wei-a.com/api/';
lanYun.wapUrl = 'file:///D:/work/APIcloud/LY/html/';
var onShow = function(){},_page = {}, pageParam = null;
!(function(HH) {
	HH.loadingMsg = '<span>正在努力加载数据..</span>';
	HH.loadingNoMsg = '-- 这已经底线了 --';
	HH.ajaxSta=0,HH.ajaxPageSta=0,HH.page=1,HH.timeout=5,HH.wait=60,HH.href = window.location.href;
	HH.getAppInfo = function() {
		var time = new Date().getTime();
		var info = {appId:'A10000001', devId:'api.deviceId',time:time};
		//info.userAgent = navigator.userAgent;
		//info.Param = md5(navigator.userAgent + info.time);
		if(isApp) {
			info = {
				jsVer:HH.ver,lan:HH.lan,sysVer:api.systemVersion,appVer:api.appVersion,devModel:api.deviceModel,devId:api.deviceId,
				appId:api.appId,osType:api.systemType,time:time,
			};
		}
		//info.sign = md5(info.appId+(info.time-HH.ver)+info.devId);
		return info;
	};
	HH.openWin = function(name , Param){
		var animation = [
			{type:'movein',subType:"from_right",duration: 300}, //从右覆盖
			{type:'push',subType:"from_right",duration: 300}, //左右推
			{type:'movein',subType:"from_bottom",duration: 300} //从下覆盖
		];
		if(!Param) Param = {frameParam:{}};
		if(!Param.frameParam) Param.frameParam = {};
		var _win = "win.html";
		var _id = name +'_win';
		Param.name = name;
		Param.ani = Param.ani ? Param.ani : 0;
		Param.backlock = Param.backlock ? true : false;
		Param.softInputMode = Param.softInputMode ? Param.softInputMode : 'auto';
		if(Param.winid) _id = Param.winid;
		if(Param.frameParam['id']) _id = Param.name + Param.frameParam['id'];
		if(Param.win && Param.win != 'none' && Param.win != 'mini') _win = Param.win+'.html';
		if(Param.id) _id += new Date().getTime();
		var pid = Param.name.split('/');Param.furl = pid[pid.length-1];
		if(!isApp){
			var wurl = Param.name;
			if(Param.name.indexOf('.html') == -1) wurl = Param.name +'/'+Param.furl+'.html';
			window.location.href = HH.wapUrl + wurl;
			return;
		}
	};

	HH.openFrame = function(name , Param , callBack) {
		var animation = [
			{type:'none'}, //无
			{type:'movein',subType:"from_right",duration: 300}, //从右覆盖
			{type:'movein',subType:"from_bottom",duration: 300} //从下覆盖
		];
		var wurl = name;
		if(name.indexOf('.html') == -1) wurl = name +'.html';
		Param.ani = Param.ani ? Param.ani : 0;
		api.openFrame({
            name: name,
            url: 'widget://html/'+ wurl,
			animation:animation[Param.ani],
            rect: {x: 0,y: 0,w: 'auto',h:'auto'},
            pageParam:Param
        });
		if(typeof(callBack) === 'function') {
			window.lyFrameCallBack = callBack;
		}
	};

	//异步 ajax
	HH.ajax = function(parm, successCall, ErrorCallBack) {

		parm.timeout = parm.timeout ? parm.timeout : HH.timeout;
		var url = HH.apiUrl + parm.url;
		if(parm.get) {
			url += '?'+HH.arrToUrlStr(parm.get);
		}
		var ajaxParm = {
			method: parm.method || "POST", url: url, timeout: parm.timeout,
			dataType:"json",
			headers: {
				"Content-Type":"application/json",
				"Content-Info": JSON.stringify(HH.getAppInfo()),
				"Content-Typek": HH.getToken()
			}
		};
		var successFun = function(ret) {
			HH.debug && console.log(JSON.stringify(ret)+'--'+HH.href);
			if(ret.errcode == 100){
				HH.loginOut();
				isApp && api.execScript({name: 'root',script:'needLoginCall('+JSON.stringify(ret)+');'});
				return false;
			}
			if(ret.needupdate==1){
				isApp && api.execScript({name: 'root',script:'needUpdateCall('+JSON.stringify(ret.updateData)+');'});
			}
			successCall && successCall(ret);
		};
		var errorFun = function(err,msg) {
			HH.debug && console.log(JSON.stringify(ret)+'--'+HH.href);
			err.href = HH.href;
			HH.ajaxSta = 0;
			isApp && api.execScript({name: 'root',script:'errorCallBack('+JSON.stringify(err)+');'});
			ErrorCallBack && ErrorCallBack(err);
		};
		if(parm.loading){
			HH.showProgress({mask:'rgba(0,0,0, 0.1)'});
		}

		ajaxParm.timeout = parm.timeout * 1000;
		ajaxParm.type = ajaxParm.method;
		if(parm.body) ajaxParm.data = JSON.stringify(parm.body);
		ajaxParm.error = errorFun;
		ajaxParm.success = successFun;
		$.ajax(ajaxParm);

	};

	HH.arrToUrlStr = function(param) {
		if(!param) return '';
		var paramStr = '';
		for (var i in param) {
			paramStr += i+'='+encodeURIComponent(param[i])+'&';
		}
		return paramStr.substring(0, paramStr.length - 1);
	};
	//设置倒计时
	HH.setWait = function(tis) {
		var el = $(tis);
		if(HH.wait == 0) {
			el.removeClass("on");
			el.html('获取验证码');
			clearTimeout(HH.timeout);
			HH.rmStorage('wait');
			HH.wait = 60;
		}else {
			el.addClass("on");
			el.html(HH.wait+"s");
			HH.wait--;
			HH.setStorage('wait', HH.wait);
			HH.timeout = setTimeout(function() {
				HH.setWait(tis);
			},1000);
		}
	};
	/*判断是否需要登录*/
	HH.isLogin = function() {
		//return false;
		if(!HH.getToken()) {
			return false;
		}
		if(!HH.getUdata()){
			return false;
		}
		return true;
	};

	HH.openLogin = function (back) {
		HH.openWin('login', {
			//win:'win',
			backlock:back,ani:0,
			title:'',frameParam : {},
		});
	};
	// token
	HH.getToken = function() {
		var token = HH.getStorage('token');
		if(!token){
			return HH.debugtoken;
		}
		return token;
	};
	//获取本地用户信息
	HH.getUdata = function() {
		HH.uData = HH.getStorage('UserData');
		if(!HH.uData){
			return null;
		}
		return HH.uData;
	};
	/*登录成功*/
	HH.loginOk = function(udata){
		HH.setStorage('token', udata.access_token);
		HH.setStorage('UserData', udata);
		api.execScript({
			name: 'root',
			script: 'loginCallback('+JSON.stringify(udata)+');'
		});
	};
	/*更新用户信息*/
	HH.updateUdata = function(udata, send){
		HH.setStorage('UserData', udata);
		if(send == 1){
			api.execScript({name: 'root',script: 'updateUdataback();'});
		}
	};
	/*退出登录*/
	HH.loginOut = function(send){
		HH.rmStorage('UserData');
		HH.rmStorage('token');
		if(send == 1){
			api.execScript({name:'root',script:'loginOutCallback();'});
		}
	};
	HH.event = function (type) {
		isApp && api.execScript({name:'root',script:'listenerEvent("'+type+'");'});
	};

})(lanYun);

!(function(HH) {
	HH.newVue = function(id,param,callBack,created,updated) {
		var cahceData = HH.getStorage(window.location.pathname);
		if(HH.isNull(cahceData)) cahceData = {listData:[]};
		var data = {noData:null,loadingMsg:'',Pdata:cahceData};
		if(typeof(param) == 'function') {
			callBack = param;
		}else{
			HH.extend(data,param);
		}
		console.log(JSON.stringify(data));
		HH.vue = new Vue({ el:id,
			data:data,
			created:callBack.created,
			mounted:function(tis){
				var data = JSON.parse(JSON.stringify(this.$data));
				callBack(data);
			},
			updated:callBack.updated
		});
	};

	HH.getVueData = function( options , successFun) {
		if(HH.ajaxPageSta==1) return;HH.ajaxPageSta = 1;
		if(HH.page>=2) HH.vue.loadingMsg = HH.loadingMsg;
		this.ajax( options , function(ret) {
			//console.log(JSON.stringify(ret));
			if(HH.page == 1){
				if(options.cache){
					HH.setStorage(window.location.pathname , ret.data);
				}else{
					HH.rmStorage(window.location.pathname);
				}
				if(!ret.data || ret.data.length == 0){
					HH.vue.noData = '暂无数据..';
				}else{
					HH.vue.loadingMsg = null;
					HH.vue.Pdata = JSON.parse(JSON.stringify(ret.data));
					//console.log(HH.vue.Pdata.listData[0]);
				}
			}else{
				if(HH.isNull(ret.data.listData) || ret.data.listData.length <= 0) {
					HH.vue.loadingMsg = HH.loadingNoMsg;
					return;
				}
				HH.vue.Pdata.listData = HH.vue.Pdata.listData.concat(ret.data.listData);
			}
			HH.vue.$nextTick(function () {
				successFun && successFun(ret);
				isApp && api.parseTapmode();
			});
			HH.page++;HH.ajaxPageSta = 0;
		},function(e){
			setTimeout(function() {
				HH.ajaxPageSta = 0;
			}, 1000);
		});
	};

	HH.getVueData2 = function( options , successFun) {
		if(HH.ajaxPageSta==1) return;HH.ajaxPageSta = 1;
		if(HH.page>=2 && !HH.isNull(HH.vue)){
			HH.vue.loadingMsg = HH.loadingMsg;
		}
		this.ajax( options , function(ret) {
			var tt = options.listid ? options.listid : 'listData';
			if(HH.page == 1){
				if(!ret.data.listData || ret.data.listData.length <= 0){
					HH.vue.page.noData = '暂无数据..';
				}else{
					HH.vue.loadingMsg = null;
					HH.vue.Pdata[tt] = ret.data.listData;
				}
			}else{
				if(HH.isNull(ret.data.listData) || ret.data.listData.length <= 0) {
					HH.vue.loadingMsg = HH.loadingNoMsg;
					return;
				}
				HH.vue.Pdata[tt] = HH.vue.Pdata[tt].concat(ret.data.listData);
			}
			HH.vue.$nextTick(function () {
				successFun && successFun(ret);
				isApp && api.parseTapmode();
			});
			HH.page++;HH.ajaxPageSta = 0;
		},function(e){
			setTimeout(function() {
				HH.ajaxPageSta = 0;
			}, 1000);
		});
	};

	HH.post = function (url,data,callback, loading) {
		loading = loading ? false : true;
		if(HH.ajaxSta==1) return;HH.ajaxSta = 1;
		this.ajax({ url:url,loading:loading, method:"POST", body: data } , function(rets) {
			lanYun.ajaxSta = 0;
			callback && callback(rets);
		});
	};

	HH.get = function (url, callback, loading) {
		loading = loading ? false : true;
		if(HH.ajaxSta==1) return;HH.ajaxSta = 1;
		this.ajax({ url:url,loading:loading, method:"GET" } , function(rets) {
			lanYun.ajaxSta = 0;
			callback && callback(rets);
		});
	};


})(lanYun);

!(function(HH) {
	// index.html中设置顶部高度适配
	HH.indexSetHeader = function(id) {
		var head = document.getElementById(id);
		return HH.fixStatusBar(head);
	};
	//加载进度动画
	HH.showProgress = function(info){

	};
	//隐藏加载动画

	HH.hideProgress = function() {

	};

	//--------localStorage
	HH.uzStorage = function(){
		var ls = window.localStorage;
		return ls;
	};
	HH.setStorage = function(key, value){
		if(arguments.length === 2){
			var v = value;
			if(typeof v == 'object'){
				v = JSON.stringify(v);
				v = 'obj-'+ v;
			}else{
				v = 'str-'+ v;
			}
			var ls = HH.uzStorage();
			if(ls){
				ls.setItem(key, v);
			}
		}
	};
	HH.isNull = function(obj) {
        if(!obj || typeof(obj) == "undefined" || obj == "" || obj === "undefined") {
            return true;
        }
        return false;
    };
	HH.rmStorage = function(key){
		var ls = HH.uzStorage();
		if(ls && key){
			ls.removeItem(key);
		}
	};
	HH.clStorage = function () {
		var ls = HH.uzStorage();
		ls.clear();
	}
	HH.getStorage = function(key){
		var ls = HH.uzStorage();
		if(ls){
			var v = ls.getItem(key);
			if(!v){
				return false;
			}
			if(v.indexOf('obj-') === 0){
				v = v.slice(4);
				return JSON.parse(v);
			}else if(v.indexOf('str-') === 0){
				return v.slice(4);
			}
		}
	};
	HH.isElement = function(obj){
		return !!(obj && obj.nodeType == 1);
	};
	HH.fixStatusBar = function(el){
		if(!HH.isElement(el)){
			return 0;
		}
		var ls = HH.uzStorage();
		if(ls){
			ls.setItem('topH', api.safeArea.top);
			ls.setItem('bottomH', api.safeArea.bottom);
		}
		el.style.paddingTop = api.safeArea.top + 'px';
		return el.offsetHeight;
	};
	HH.extend = function(a, b) {
		for (var key in b) {
			if (b.hasOwnProperty(key)) {
				a[key] = b[key];
			}
		}
		return a;
	};
	HH.copy = function (data) {
		return JSON.parse(JSON.stringify(data));
	};
	HH.frameGroup = {
		group:[],
		open:function(Param) {
			var data = Param.data;
			var fname = null;
			for (var i = 0; i <= data.length-1; i++) {
				fname = 'main'+i;
				var rect = {x: 0, w:'auto',y: data[i].y, h: data[i].h, xy:data[i].xy, xh:data[i].xh };
				this.group.push(rect);
				api.openFrame({
					name:fname ,url:data[i].url,
					rect:rect,
					vScrollBarEnabled:data[i].Scroll,
					pageParam: data[i].Param,
					bounces: data[i].tan,
					bgColor:'#eee',
					hScrollBarEnabled: false
				});
			}
			api.bringFrameToFront({from: 'main'+Param.index});
		},
		show:function(id){
			var tis = this.group[id];
			for (var i = 0; i <= this.group.length-1; i++) {
				if(i == id){
					var rec = {x:0,w:'auto',y:tis.y,h:tis.h};
					if(typeof tis.xy != "undefined") rec.y = tis.xy;
					if(tis.xh) rec.h = tis.xh;
					api.setFrameAttr({name: 'main'+i, rect:rec });
				}else{
					api.setFrameAttr({name: 'main'+i, rect:tis});
				}
			}
			api.bringFrameToFront({from: 'main'+id});
		}
	};

	HH.toast = function(msg, wz , time){
		if(!isApp){
			alert(msg);
			return;
		}
		api.toast({ msg:msg, duration:time?time:2000,location:wz?wz:'bottom'});
	};

	HH.alert = function(param, callback){
		param.topFname = api.frameName;
		api.openFrame({
			name: param.id,
			url: 'widget://html/dialog/alert.html',
			rect: {x:0, y:0,w:'auto',h:'auto'},
			pageParam:param
		});
		window.nowDialogCallback = callback;
	};
	//frame 弹框 by juelie
	HH.dialog = {
		//带输入框
		input : function(param, callback){
			param.topFname = api.frameName;
			api.openFrame({
				name: param.fname,
				url: 'widget://html/dialog/input.html',
				rect: {x:0, y:0,w:'auto',h:'auto'},
				pageParam:param
			});
			window.nowDialogCallback = callback;
		},
		alert1 : function(param, callback){
			param.topFname = api.frameName;
			api.openFrame({
				name: param.fname,
				url: 'widget://html/dialog/del_botton.html',
				rect: {x:0, y:0,w:'auto',h:'auto'},
				pageParam:param
			});
			window.nowDialogCallback = callback;
		},
		//继续写新的...
	}

})(lanYun);
